package com.study.dataStructure.searchAlgorithms;

/**
 * @author tiny
 * @date 2021/11/5 23:30
 * @Description: 插值查找
 */
public class InsertValueSearch {

    public int search(int[] arr,int left,int right,int findVal) {
        if (left>right || findVal < arr[left] || findVal > arr[right]) return -1;
        int mid = (findVal - arr[left]) / (arr[right] - arr[left]) * right;

        if (arr[mid] == findVal){
            return mid;
        }else if(arr[mid] > findVal){
            return search(arr,left,mid-1,findVal);
        }else {
            return search(arr,mid+1,right,findVal);
        }
    }

}
